package com.company;

import java.util.Random;
import java.util.Scanner;

public class GuessNumber {
    public static void main(String[] args){
        Random rand = new Random();
        Scanner scan = new Scanner(System.in);
        String playAgain = null;
        do{
            int chances = 7;
            System.out.println("还有"+chances+"次机会，再猜一个1-100之间的整数");
            int answer = rand.nextInt(100) + 1;
            //System.out.println(answer);
            int guess = scan.nextInt();
            while (guess != answer && chances > 1){
            chances = chances - 1;
            if(guess < answer){
                System.out.println("猜小了！还有"+chances+"次机会，再猜一个1-100之间的整数");
            }else if(guess > answer){
                System.out.println("猜大了！还有"+chances+"次机会，再猜一个1-100之间的整数");
            }
            guess = scan.nextInt();
        }
        if (guess == answer){
            System.out.println("猜对了");
        }
        System.out.println("重完一次？(y/n)");
        playAgain = scan.next();
        }while (playAgain.equalsIgnoreCase("y"));
    }
}